package com.dongge.entity1;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2015/10/16.
 */
@Entity
@Table
public class Comment {
    private Long id;
    private String content;
    private Date commentTime;
    private String username;
    private Set<Comment> children = new HashSet<Comment>();
    private Comment parent;
    private Comment top;//第一条评论
    private Article article;

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Column
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Column
    public Date getCommentTime() {
        return commentTime;
    }

    public void setCommentTime(Date commentTime) {
        this.commentTime = commentTime;
    }

    @Column
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @OneToMany
    @JoinColumn(name = "parentId")
    @OrderBy("commentTime")
    public Set<Comment> getChildren() {
        return children;
    }

    public void setChildren(Set<Comment> children) {
        this.children = children;
    }

    @ManyToOne
    @JoinColumn(name = "parentId")
    public Comment getParent() {
        return parent;
    }

    public void setParent(Comment parent) {
        this.parent = parent;
    }

    @ManyToOne
    @JoinColumn(name = "topId")
    public Comment getTop() {
        return top;
    }

    public void setTop(Comment top) {
        this.top = top;
    }

    @ManyToOne(targetEntity = Article.class)
    @JoinColumn(name = "articleId")
    public Article getArticle() {
        return article;
    }

    public void setArticle(Article article) {
        this.article = article;
    }
}
